import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;

public class NodeQuestInterface {
	/*
	Player player;
	InterfaceFrame frame;
	ArrayList<String> questOptions = new ArrayList<String>();
	Quest quest;
	CustomButton next;
	CustomButton option1 = new CustomButton();
	CustomButton option2 = new CustomButton();
	CustomButton option3 = new CustomButton();
	CustomButton option4 = new CustomButton();
	CustomButton option5 = new CustomButton();
	CustomButton option6 = new CustomButton();
	protected int currentQuestLogLevel = 0;
	protected int finalQuestLogLevel = 0;
	String[][] QuestLogLevels = new String[20][6];
	final int ENLARGE_VALUE = 100;
	MapNode node;
	
	NodeQuestInterface(Player player, InterfaceFrame frame, MapNode node){
		this.player = player;
		this.frame = frame;
		this.node = node;
		quest = frame.map.allQuests.get(node.activeQuestIndex);
		questOptions = quest.alternativeResponses;
		option1.addActionListener(new ButtonListener());
		option2.addActionListener(new ButtonListener());
		option3.addActionListener(new ButtonListener());
		option4.addActionListener(new ButtonListener());
		option5.addActionListener(new ButtonListener());
		option6.addActionListener(new ButtonListener());
		option1.addMouseListener(new TheMouseListener());
		option2.addMouseListener(new TheMouseListener());
		option3.addMouseListener(new TheMouseListener());
		option4.addMouseListener(new TheMouseListener());
		option5.addMouseListener(new TheMouseListener());
		option6.addMouseListener(new TheMouseListener());
		
		if (!player.activeQuests.contains(frame.map.allQuests.get(node.activeQuestIndex).questNo) && (frame.map.allQuests.get(node.activeQuestIndex).alternativeResponses.size() > 0))
			player.activeQuests.add(frame.map.allQuests.get(node.activeQuestIndex).questNo);
		
	}
	
	public ImageIcon getQuestPic(){
		
		quest = frame.map.allQuests.get(node.activeQuestIndex);
		return new ImageIcon(getClass().getResource(quest.questPic));
	}
	
	public void showQuestOptions(){
		frame.nface.addQuestLogIfNeeded();
		quest = frame.map.allQuests.get(node.activeQuestIndex);
		questOptions = quest.alternativeResponses;
		
		quest.getRewards(player, node);
		removeQuestButtonIfNeeded();
		
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));

		if(questOptions.size() > 0){
			option1.setText(questOptions.get(0));
			frame.nface.popOptions.add(option1);
		}
		else
			frame.nface.popOptions.remove(option1);
		
		if(questOptions.size() > 1){
			option2.setText(questOptions.get(1));
			frame.nface.popOptions.add(option2);
		}
		else
			frame.nface.popOptions.remove(option2);
		
		if(questOptions.size() > 3){
			option3.setText(questOptions.get(2));
			frame.nface.popOptions.add(option3);
		}
		else
			frame.nface.popOptions.remove(option3);
		
		if(questOptions.size() > 4){
			option4.setText(questOptions.get(3));
			frame.nface.popOptions.add(option4);
		}
		else
			frame.nface.popOptions.remove(option4);
		
		if(questOptions.size() > 5){
			option5.setText(questOptions.get(4));
			frame.nface.popOptions.add(option5);
		}
		else
			frame.nface.popOptions.remove(option5);
		
		if(questOptions.size() > 6){
			option6.setText(questOptions.get(5));
			frame.nface.popOptions.add(option6);
		}
		else
			frame.nface.popOptions.remove(option6);
		
	}
	
	public void removeQuestButtonIfNeeded(){
		if(node.activeQuestIndex == -1){
			frame.nface.popPrime.remove(frame.nface.quest);
			frame.getContentPane().repaint();
			
		}
		
	}
	
	private class CustomButton extends JButton{
		
		private static final long serialVersionUID = 1L;

		CustomButton(){
			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(306,50);	
		}
		
	}
	
	private class ButtonListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			
			if(e.getSource().equals(option1)){
				quest.chooseAlternative(frame.map, player, 0);
				frame.nface.imageLabel.setIcon(getQuestPic());
				showQuestOptions();
				frame.nface.textArea.setText(quest.dialog);
				frame.nface.addQuestLogIfNeeded();
				removeQuestButtonIfNeeded();
				frame.getContentPane().repaint();
			}
			
			else if(e.getSource().equals(option2)){
				quest.chooseAlternative(frame.map, player, 1);
				frame.nface.imageLabel.setIcon(getQuestPic());
				showQuestOptions();
				frame.nface.textArea.setText(quest.dialog);
				frame.nface.addQuestLogIfNeeded();
				removeQuestButtonIfNeeded();
				frame.getContentPane().repaint();
			}
			
			else if(e.getSource().equals(option3)){
				quest.chooseAlternative(frame.map, player, 2);
				frame.nface.imageLabel.setIcon(getQuestPic());
				showQuestOptions();
				frame.nface.textArea.setText(quest.dialog);
				frame.nface.addQuestLogIfNeeded();
				removeQuestButtonIfNeeded();
				frame.getContentPane().repaint();
			}
			
			else if(e.getSource().equals(option4)){
				quest.chooseAlternative(frame.map, player, 3);
				frame.nface.imageLabel.setIcon(getQuestPic());
				showQuestOptions();
				frame.nface.textArea.setText(quest.dialog);
				frame.nface.addQuestLogIfNeeded();
				removeQuestButtonIfNeeded();
				frame.getContentPane().repaint();
			}
			
			else if(e.getSource().equals(option5)){
				quest.chooseAlternative(frame.map, player, 4);
				frame.nface.imageLabel.setIcon(getQuestPic());
				showQuestOptions();
				frame.nface.textArea.setText(quest.dialog);
				frame.nface.addQuestLogIfNeeded();
				removeQuestButtonIfNeeded();
				frame.getContentPane().repaint();
			}
			
			else if(e.getSource().equals(option6)){
				quest.chooseAlternative(frame.map, player, 5);
				frame.nface.imageLabel.setIcon(getQuestPic());
				showQuestOptions();
				frame.nface.textArea.setText(quest.dialog);
				frame.nface.addQuestLogIfNeeded();
				removeQuestButtonIfNeeded();
				frame.getContentPane().repaint();
			}
			
		}
		
	}
	
	private class TheMouseListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e){
		}

		@Override
		public void mouseEntered(MouseEvent e) {
		}

		@Override
		public void mouseExited(MouseEvent e) {
		}
		
		@Override
		public void mousePressed(MouseEvent e) {
			frame.nface.popPrime.show(frame, 50, 55);
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			
		}
		
	}*/
}
